<template>
  <div>
    <!-- 导航面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            v-model="queryInfo.query"
            clearable
          >
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-row>
        <el-table :data="orderlist" border stripe>
          <el-table-column label="#" type="index"> </el-table-column>
          <el-table-column label="订单编号" prop="order_number">
          </el-table-column>
          <el-table-column label="订单价格" prop="order_price">
          </el-table-column>
          <el-table-column label="是否付款" prop="pay_status">
            <template slot-scope="scoped">
              <el-tag type="success" v-if="scoped.row.pay_status === '1'"
                >已付款</el-tag
              >
              <el-tag type="danger" v-else>未付款</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="是否发货" prop="is_send"> </el-table-column>
          <el-table-column label="下单时间" prop="create_time">
            <template slot-scope="scoped">
              {{ scoped.row.create_time | dateFormat }}
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scoped">
              <el-button
                type="primary"
                icon="el-icon-edit"
                circle
                @click="handleEdit(scoped.row.order_id)"
              ></el-button>
              <el-button
                type="success"
                icon="el-icon-location"
                circle
              ></el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          background
        >
        </el-pagination>
      </el-row>
      <!-- 编辑弹出框 -->
      <el-dialog
        title="编辑"
        :visible.sync="editVisible"
        width="50%"
        @close="editClose"
      >
        <el-form
          :model="addressForm"
          :rules="addressFormRules"
          ref="addressFormRef"
          label-width="100px"
        >
          <el-form-item label="省市区/县" prop="addressForm1">
            <el-cascader
              v-model="addressForm.addressForm1"
              :options="cityData"
              @change="handleChange"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="addressForm2">
            <el-input v-model="addressForm.addressForm2"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="editVisible = false">取 消</el-button>
          <el-button type="primary" @click="editVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data() {
    return {
      cityData,
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
      },
      orderlist: [],
      total: 0,
      editVisible: false,
      addressForm: {
        addressForm1: [],
        addressForm2: '',
      },
      addressFormRules: {
        addressForm1: [
          { required: true, message: '请选择位置信息', trigger: 'blur' },
        ],
        addressForm2: [
          { required: true, message: '请填写详细位置信息', trigger: 'blur' },
        ],
      },
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo,
      })
      console.log('order:', res)
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单信息失败')
      }
      this.$message.success('获取订单成功')
      this.orderlist = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    handleCurrentChange(newCurrent) {
      this.queryInfo.pagenum = newCurrent
      this.getOrderList()
    },
    // 编辑
    handleEdit() {
      this.editVisible = true
    },
    handleChange() {},
    editClose() {
      this.editVisible = false
      this.$refs.addressFormRef.resetFields()
    },
  },
}
</script>

<style lang="less" scoped>
.el-cascader {
  width: 100%;
}
.el-input__inner {
  width: 100%;
}
</style>
